package com.yh.db;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.omg.CORBA.PUBLIC_MEMBER;

public class SqlSessionFactoryUtil {

	public static SqlSessionFactory sqlSessionFactory =  null;
	static{
		String resource = "mybatis.xml";
		//读取配置文件,获取数据源的连接信息
		try {
			InputStream ins  = Resources.getResourceAsStream(resource);
			sqlSessionFactory = new SqlSessionFactoryBuilder().build(ins);
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
					
	}
  public static SqlSession getSqlSession(){
	  return sqlSessionFactory.openSession();
  }
}
